package com.example.demo.service.serviceImpl;

import com.example.demo.entity.Reservation;
import com.example.demo.entity.Stadium;
import com.example.demo.entity.User;
import com.example.demo.mapper.ReservationMapper;
import com.example.demo.mapper.StadiumMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private UserMapper usermapper;/*返回方法建议是返回值的全小写或首字母小写*/
    @Autowired
    private StadiumMapper stadiummapper;
    @Autowired
    private ReservationMapper reservationmapper;

    @Override
    public User findUserId(User user){
        User user1 = usermapper.findUserID(user);
        return user1;
    }
    @Override
    public List<Stadium> findAllStadiums(){
        //System.out.println("start"+System.currentTimeMillis());/*记录时间日志*/
        List<Stadium> stadiums=stadiummapper.findAllStadiums();
        //System.out.println("end"+System.currentTimeMillis());/*记录时间日志*/
        return stadiums;
    }
    @Override
    public User findAUsers(String username){
        //System.out.println("start"+System.currentTimeMillis());/*记录时间日志*/
        User users=usermapper.findAUsers(username);
        //System.out.println("end"+System.currentTimeMillis());/*记录时间日志*/
        return users;
    }
    @Override
    public List<Stadium> findStadiumsByType(String type){
        //System.out.println("start"+System.currentTimeMillis());/*记录时间日志*/
        List<Stadium> stadiums=stadiummapper.findStadiumByType(type);
        //System.out.println("end"+System.currentTimeMillis());/*记录时间日志*/
        return stadiums;
    }

    @Override
    public List<Reservation> findReservationsByType(String type){
        //System.out.println("start"+System.currentTimeMillis());/*记录时间日志*/
        List<Reservation> reservations=reservationmapper.findReservationByType(type);
        //System.out.println("end"+System.currentTimeMillis());/*记录时间日志*/
        return reservations;
    }

    @Override
    public int addStadiums(Stadium stadium){
        int i = stadiummapper.addStadium(stadium);
        return i;
    }

    @Override
    public int findStadiumIdByNumber(Stadium stadium){
        try {

            List<Integer> i = stadiummapper.findStadiumIdByNumber(stadium);
            if(!i.isEmpty()) {
                System.out.print("s_id:");
                System.out.println(i);
                return 1;
            }
            else{
                return 0;
            }

        }catch (Exception e){
            System.out.println("s_id为空");
            return 0;
        }
    }

    @Override
    public int deleteStadium(int s_id){
        int i=stadiummapper.deleteStadium(s_id);
        return i;
    }
}
